import Vue from 'vue'
import Vuex from 'vuex'

import users from "./modules/users"

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: '',
    userName: '',
    menuObj:'',
    menuActive: ''
  },
  mutations: {
    setToken(state,data){
      state.Token=data;
      window.localStorage.setItem("myToken",data);
    },
    setUserName(state,data){
      state.userName=data;
      window.localStorage.setItem('userName',data);
    },
    setMenuObj(state,data){
      state.menuObj=data;
      window.sessionStorage.setItem('menuObj',JSON.stringify(data));
    },
    setMenuActive(state,data){
      state.menuActive=data;
      window.sessionStorage.setItem('menuActive',data);
    }
  },
  actions: {},
  getters:{
    getToken(state){
      return state.token || window.localStorage.getItem('myToken');
    },
    getUserName(state){
      return state.userName || window.localStorage.getItem('userName');
    },
    getMenuObj(state){
      return state.menuObj || JSON.parse( window.sessionStorage.getItem('menuObj')) || '';
    },
    getMenuActive(state){
      return state.menuActive || window.sessionStorage.getItem('menuActive');
    }
  },
  modules: {
    users
  }
})
